package cn.huobi.basic.controller;

import cn.huobi.basic.dto.EmailCodeDto;
import cn.huobi.basic.dto.GetSmsCodeDto;
import cn.huobi.basic.dto.PhoneSmsCodeDto;
import cn.huobi.basic.dto.SmsCodeLoginDto;
import cn.huobi.basic.service.VerifyCodeService;
import cn.huobi.basic.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.Email;

@RestController
@RequestMapping("/verifyCode")
public class VerifyCodeController {

    @Autowired
    private VerifyCodeService verifyCodeService;

    /**
     * 获取 图形验证码
     */
    @GetMapping("/image/{key}")
    public AjaxResult getImageCode(@PathVariable("key") String uuidKey){
        String base64Code = verifyCodeService.getImageCode(uuidKey);
        return AjaxResult.me().success(base64Code);
    }

    /**
     * 获取 手机号注册 短信验证码
     */
    @PostMapping("/smsCode")
    public AjaxResult smsCode(@RequestBody @Valid PhoneSmsCodeDto phoneSmsCodeDto){
        verifyCodeService.smsCode(phoneSmsCodeDto);
        return AjaxResult.me().success();
    }

    /**
     * 获取 邮箱注册 验证码
     */
    @PostMapping("/emailCode")
    public AjaxResult emailCode(@RequestBody @Valid EmailCodeDto emailCodeDto){
        verifyCodeService.emailCode(emailCodeDto);
        return AjaxResult.me().success();
    }

    /**
     * 获取 短信登录 验证码
     */
    @PostMapping("/smsCodeLogin")
    public AjaxResult smsCodeLogin(@RequestBody @Valid SmsCodeLoginDto smsCodeLoginDto){
        verifyCodeService.smsCodeLogin(smsCodeLoginDto);
        return AjaxResult.me().success();
    }
}
